﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsDMSanPhamCongViec
    {
        private int mActive = 0;
        private string mDienGiai = "";
        private double mDuToanChiPhi = 0.0;
        private double mDuToanDoanhThu = 0.0;
        private int mKetThuc = 0;
        private string mKhoa = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaNhanVien = "";
        private string mKhoaNhanVienCapNhat = "";
        private string mLoaiTien = "";
        private string mMa = "";
        private string mNgayBatDau = "";
        private string mNgayKetThuc = "";
        private int mSend = 0;
        private string mTenAnh = "";
        private string mTenViet = "";
        private int mTheoDoiCongDoan = 0;
        private string mTuNgay = "";

        public bool DelData(string pKhoa)
        {
            IDataParameter parameter = null;
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "DELETE FROM DM_SanPhamCongViec WHERE Khoa = '" + pKhoa.Trim() + "'";
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM DM_SanPhamCongViec WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mMa = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mTenViet = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mTenAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNgayBatDau = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKetThuc = Conversions.ToInteger(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetInt32));
                    this.mNgayKetThuc = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mDuToanChiPhi = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mDuToanDoanhThu = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mTuNgay = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienCapNhat = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mActive = Conversions.ToInteger(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetInt32));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetInt32));
                    this.mTheoDoiCongDoan = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetInt32));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[0x12];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@Ma", DbType.Int64, ParameterDirection.Input, this.mMa);
                commandParameters[2] = DBHelper.createParameter("@TenViet", DbType.Int64, ParameterDirection.Input, this.mTenViet);
                commandParameters[3] = DBHelper.createParameter("@TenAnh", DbType.Int64, ParameterDirection.Input, this.mTenAnh);
                commandParameters[4] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[5] = DBHelper.createParameter("@NgayBatDau", DbType.Int64, ParameterDirection.Input, this.mNgayBatDau);
                commandParameters[6] = DBHelper.createParameter("@KetThuc", DbType.Double, ParameterDirection.Input, this.mKetThuc);
                commandParameters[7] = DBHelper.createParameter("@NgayKetThuc", DbType.Int64, ParameterDirection.Input, this.mNgayKetThuc);
                commandParameters[8] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[9] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVien);
                commandParameters[10] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[11] = DBHelper.createParameter("@DuToanChiPhi", DbType.Date, ParameterDirection.Input, this.mDuToanChiPhi);
                commandParameters[12] = DBHelper.createParameter("@DuToanDoanhThu", DbType.Date, ParameterDirection.Input, this.mDuToanDoanhThu);
                commandParameters[13] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, this.mTuNgay);
                commandParameters[14] = DBHelper.createParameter("@KhoaNhanVienCapNhat", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienCapNhat);
                commandParameters[15] = DBHelper.createParameter("@Active", DbType.Double, ParameterDirection.Input, this.mActive);
                commandParameters[0x10] = DBHelper.createParameter("@Send", DbType.Double, ParameterDirection.Input, this.mSend);
                commandParameters[0x11] = DBHelper.createParameter("@TheoDoiCongDoan", DbType.Double, ParameterDirection.Input, this.mTheoDoiCongDoan);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "sp_DM_SanPhamCongViec", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public string SearchByCode(string strCode = "", string strKeyFilter = "", string strFiledNameFilter = "")
        {
            string str5;
            string commandText = "";
            IDataParameter parameter = null;
            string str4 = "";
            string str2 = "";
            string str = "";
            try
            {
                if (strCode.Trim() != "")
                {
                    str4 = " AND RTRIM(Ma) = '" + strCode.Trim() + "'";
                }
                if (strKeyFilter.Trim() != "")
                {
                    object instance = Strings.Split(strKeyFilter, "|", -1, CompareMethod.Binary);
                    int num2 = Information.UBound((Array) instance, 1);
                    for (int i = 0; i <= num2; i++)
                    {
                        if (str2.Trim() == "")
                        {
                            str2 = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                        else
                        {
                            str2 = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(str2 + ",'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                    }
                    str4 = str4 + " AND " + strFiledNameFilter + " IN (" + str2 + ")";
                }
                commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as Ten  FROM DM_SanPhamCongViec WHERE Active = 1 " + str4;
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter });
                if (dataReader.Read())
                {
                    str = modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString).ToString();
                }
                dataReader.Close();
                str5 = str;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                str5 = "";
                ProjectData.ClearProjectError();
                return str5;
                ProjectData.ClearProjectError();
            }
            return str5;
        }

        public DataTable ShowAllList()
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM DM_SanPhamCongViec ORDER BY Ma ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable ShowList(string strKeyFilter = "", string strFiledNameFilter = "")
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            string str3 = "";
            string str = "";
            try
            {
                if (strKeyFilter.Trim() != "")
                {
                    object instance = Strings.Split(strKeyFilter, "|", -1, CompareMethod.Binary);
                    int num2 = Information.UBound((Array) instance, 1);
                    for (int i = 0; i <= num2; i++)
                    {
                        if (str.Trim() == "")
                        {
                            str = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                        else
                        {
                            str = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(str + ",'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                    }
                    str3 = " AND " + strFiledNameFilter + " IN (" + str + ")";
                }
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM DM_SanPhamCongViec WHERE Active = 1 " + str3 + " ORDER BY Ma ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable ShowListByField(string strFieldList, string strConditions = "", string strOrder = "")
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            string str3 = "";
            string str = "";
            strFieldList = Strings.Replace(strFieldList, "|", ",", 1, -1, CompareMethod.Binary);
            try
            {
                if (strConditions.Trim() != "")
                {
                    str3 = " WHERE " + strConditions;
                }
                if (strOrder.Trim() != "")
                {
                    str = " ORDER BY " + strOrder;
                }
                commandText = " SELECT " + strFieldList + "  FROM DM_SanPhamCongViec " + str3 + str;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool TrungMa(string pMa, string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM DM_SanPhamCongViec WHERE RTRIM(Ma) = '" + pMa.Trim() + "' AND RTRIM(Khoa) <> '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public bool WasUsed(string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM DM_SanPhamCongViec WHERE RTRIM(Khoa) = '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public int Active
        {
            get
            {
                return this.mActive;
            }
            set
            {
                this.mActive = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public double DuToanChiPhi
        {
            get
            {
                return this.mDuToanChiPhi;
            }
            set
            {
                this.mDuToanChiPhi = value;
            }
        }

        public double DuToanDoanhThu
        {
            get
            {
                return this.mDuToanDoanhThu;
            }
            set
            {
                this.mDuToanDoanhThu = value;
            }
        }

        public int KetThuc
        {
            get
            {
                return this.mKetThuc;
            }
            set
            {
                this.mKetThuc = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaNhanVien
        {
            get
            {
                return this.mKhoaNhanVien;
            }
            set
            {
                this.mKhoaNhanVien = value;
            }
        }

        public string KhoaNhanVienCapNhat
        {
            get
            {
                return this.mKhoaNhanVienCapNhat;
            }
            set
            {
                this.mKhoaNhanVienCapNhat = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string Ma
        {
            get
            {
                return this.mMa;
            }
            set
            {
                this.mMa = value;
            }
        }

        public string NgayBatDau
        {
            get
            {
                return this.mNgayBatDau;
            }
            set
            {
                this.mNgayBatDau = value;
            }
        }

        public string NgayKetThuc
        {
            get
            {
                return this.mNgayKetThuc;
            }
            set
            {
                this.mNgayKetThuc = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string TenAnh
        {
            get
            {
                return this.mTenAnh;
            }
            set
            {
                this.mTenAnh = value;
            }
        }

        public string TenViet
        {
            get
            {
                return this.mTenViet;
            }
            set
            {
                this.mTenViet = value;
            }
        }

        public int TheoDoiCongDoan
        {
            get
            {
                return this.mTheoDoiCongDoan;
            }
            set
            {
                this.mTheoDoiCongDoan = value;
            }
        }

        public string TuNgay
        {
            get
            {
                return this.mTuNgay;
            }
            set
            {
                this.mTuNgay = value;
            }
        }
    }
}

